// Package coding_round_1 19-61
// @Title coding_round_1
// @Description
// @Author  == 琳琳也叫王木木 ==  2021/9/10 11:38
// @Create  2021/9/10 11:38
package coding_round_1

// 旋转链表的k个变量
func RotateRight(head *ListNode, k int) *ListNode {
	if k == 0 || head == nil || head.Next == nil {
		return head
	}
	n := 1
	iter := head
	for iter.Next != nil {
		iter = iter.Next
		n++
	}
	add := n - k%n
	if add == n {
		return head
	}
	iter.Next = head
	for add > 0 {
		iter = iter.Next
		add--
	}
	ret := iter.Next
	iter.Next = nil
	return ret
}
